<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/8/2
 * Time: 10:22
 */
namespace app\index\model;

use think\Model;

class Orders extends Model
{
    public function payh5($openid,$total_fee,$body,$out_trade_no){
        $config= config('wxpay');
        $ip= request()->ip();
        $url = "https://api.mch.weixin.qq.com/pay/unifiedorder";
        $notify_url ='http://'.$_SERVER['HTTP_HOST'].'/index/index/notify';

        $onoce_str = $this->createNoncestr();

        $data["appid"] = $config['appid'];
        $data["body"] = $body;
        $data["mch_id"] = $config['mch_id'];
        $data["nonce_str"] = $onoce_str;
        $data["notify_url"] = $notify_url;
        $data["out_trade_no"] = $out_trade_no;
        $data["spbill_create_ip"] = $ip;
        $data["total_fee"] = $total_fee;
        $data["trade_type"] = "MWEB";

        $data["scene_info"] = "{'h5_info': {'type':'Wap','wap_url': $notify_url,'wap_name': '测试充值'}}";
        $sign = $this->getSign($data);
// halt($data);
        $data["sign"] = $sign;

        $xml = $this->arrayToxml($data);
        $response = $this->postxmlCurl($xml, $url);



//将微信返回的结果xml转成数组
        $response = $this->xmlToArray($response);





//请求数据,统一下单

        return $response;
    }
}